#pragma once
#include "IComponentSystem.h"
#include "IMouseListener.h"

#include <list>

namespace ZeEngine
{
    class GUIObject;

    class GUISystem : public IComponentSystem, public IMouseListener
    {
    public:
        GUISystem();
        virtual ~GUISystem();

        //System override
        virtual bool Init(GameEngine& gameEngine) override;
        virtual bool Update(GameEngine& gameEngine) override;
        virtual void Destroy(GameEngine& gameEngine) override;
        virtual void Render(SDL_Renderer& renderer, GameEngine& gameEngine, float interpolation) override;

        void AddControl(std::shared_ptr<GUIObject> pObject);
        void RemoveControl(std::shared_ptr<GUIObject> pObject);

        std::shared_ptr<GUIObject> GetControl(u32 id) const;

        //IMouseListener
        virtual bool OnMouseMoved(const Vector2D<s32>& absolute, const Vector2D<s32>& relative) override;
        virtual bool OnMouseButtonPressed(const Vector2D<s32>& absolute, s32 button) override;
        virtual bool OnMouseButtonReleased(const Vector2D<s32>& absolute, s32 button) override;

    private:
        void Render(SDL_Renderer& renderer, GUIObject& object);

    private:
        std::list<std::shared_ptr<GUIObject>> m_controls;
        std::shared_ptr<GUIObject>            m_currentControl;
    };
}

